using JavaVirtualMachine;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DrawList : DrawBase
{
    public Button button;
    [HideInInspector]
    public Image image;
    public Text text;
    public int index;
    public int addr;
    private GameGraphics gameGraphics;
    public bool isOnClick;
    private void Awake()
    {
        image = button.image;
    }
    // Start is called before the first frame update
    void Start()
    {
        button.onClick.AddListener(OnClick);
    }

    public void SetImageColor(bool isSelect=true)
    {
        image.color = isSelect ?   Color.yellow: Color.white;
        isOnClick = isSelect;
    }

    public void DrawListItem( List_ item,int id)
    {
        this.gameGraphics = GameGraphics.Ins;
        text.text = item.name;
        gameObject.SetActive(true);
        this.index = transform .GetSiblingIndex()-1;
        addr = id;
        isOnClick = false;
        SetImageColor(false);
    }

    public void OnClick()
    {
        if (isOnClick)
        {
            isOnClick = false;
            Program.CallListCommandActionMethod(addr, gameGraphics.displayableId);
        }
        else
        {
            isOnClick = true;
            Program.CallListSetSelectedIndexMethod(addr, index);
            SetImageColor(true);
            GameGraphics.Ins.SetCurrentSelectListItem(this);
        }
    }
}
